package com.tuanzi.loan.business.service.family.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tuanzi.loan.business.entity.family.UserCreditRecord;
import com.tuanzi.loan.business.entity.family.UserCreditRecordSourceType;
import com.tuanzi.loan.business.repository.family.UserCreditRecordRepository;
import com.tuanzi.loan.business.service.family.UserCreditRecordService;
import com.tuanzi.loan.core.aspect.Debug;

/**
 * @author Ray 2017/09/21
 */
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class UserCreditRecordServiceImpl implements UserCreditRecordService {

	@Autowired
	private UserCreditRecordRepository userCreditRecordRepository;

	@Override
	public List<UserCreditRecord> findAllBaiduJRByPhones(List<String> phones) {
		return userCreditRecordRepository.findAllByPhoneInAndSourceType(phones, UserCreditRecordSourceType.BAIDU_JR);
	}

	@Override
	public List<UserCreditRecord> findAllDianJinByPhones(List<String> phones) {
		return userCreditRecordRepository.findAllByPhoneInAndSourceType(phones, UserCreditRecordSourceType.DIAN_JIN);
	}

	@Override
	public List<UserCreditRecord> findAllByUserId(Long userId) {
		return userCreditRecordRepository.findAllByUserId(userId);
	}

	@Override
	public List<UserCreditRecord> findAllByUserIdAndSourceType(Long userId, UserCreditRecordSourceType sourceType) {
		return userCreditRecordRepository.findAllByUserIdAndSourceType(userId, sourceType);
	}
}
